using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using LayuiBlazor.Extensions;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace LayuiBlazor.Components
{
    /// <summary>
    /// Bootstrap Blazor 组件基类
    /// </summary>
    public abstract class LayuiComponentBase : ComponentBase
    {
        /// <summary>
        /// 获得/设置 用户自定义属性
        /// </summary>
        [Parameter(CaptureUnmatchedValues = true)]
        public IDictionary<string, object> AdditionalAttributes { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 获得/设置 IJSRuntime 实例
        /// </summary>
        [Inject]
        [NotNull]
        protected IJSRuntime JSRuntime { get; set; }

        [Inject]
        [NotNull]
        private IServiceProvider Provider { get; set; }

        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            ServiceProviderHelper.RegisterProvider(Provider);
        }
    }
}
